package com.jasonzhou.onetomanycontrol.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding


/**
 * Created by Jason_周 on 2016/11/17.
 */
class ViewHolder<T : ViewBinding>(val t: T) : RecyclerView.ViewHolder(t.root)
abstract class CommonAdapter<T, V : ViewBinding>(protected var mContext: Context?, protected var datas: List<T>) :
    RecyclerView.Adapter<ViewHolder<V>>() {
    protected var mInflater: LayoutInflater = LayoutInflater.from(mContext)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder<V> {
        return ViewHolder(getViewBinding(parent, viewType))
    }

    override fun onBindViewHolder(holder: ViewHolder<V>, position: Int) {
        convert(holder.t, datas[position], position)
    }

    abstract fun getViewBinding(parent: ViewGroup, viewType: Int): V
    abstract fun convert(v: V, t: T, position: Int)


    override fun getItemCount(): Int {
        return datas.size
    }

}
